//
//运行环境配置
//

//运行参数
//flutter run --dart-define=ENV_MODEL=test
//flutter run --dart-define=ENV_MODEL=prod
//flutter run -d chrome --web-hostname 192.168.0.189 --web-port 5787

//打包参数
//flutter build apk --dart-define=ENV_MODEL=test
//flutter build apk --dart-define=ENV_MODEL=prod
//以下打包前提是xcode中已配置好ad-hoc证书或者已登录开发账号并勾选了证书自动托管
//flutter build ipa --export-method ad-hoc --dart-define=ENV_MODEL=test
//flutter build ipa --export-method ad-hoc --dart-define=ENV_MODEL=prod


class Env {
  //获取运行时传入的环境变量
  static const appEnv = String.fromEnvironment(EnvArgs.envKey);

  //开发环境配置
  static final EnvConfig _devConfig = EnvConfig(
    baseUrl: 'http://dev/',
    webUrl: 'http://dev/',
  );

  //测试环境配置
  static final EnvConfig _testConfig = EnvConfig(
    baseUrl: 'https://test/',
    webUrl: 'https://test/',
  );

  //生产环境配置
  static final EnvConfig _prodConfig = EnvConfig(
    baseUrl: 'https://prod/',
    webUrl: 'https://prod/',
  );

  //默认环境
  static EnvConfig envConfig = _prodConfig;

  //根据传入配置判断返回当前环境
  static _getEnvConfig() {
    switch (appEnv) {
      case EnvArgs.dev:
        envConfig = _devConfig;
        break;
      case EnvArgs.test:
        envConfig = _testConfig;
        break;
      case EnvArgs.prod:
        envConfig = _prodConfig;
        break;
    }
  }

  static initEnvConfig() => _getEnvConfig();
}

//环境值声明
class EnvArgs {
  //环境key
  static const String envKey = "ENV_MODEL";

  //环境value
  static const String dev = "dev";
  static const String test = "test";
  static const String prod = "prod";
}

//环境配置信息model
class EnvConfig {
  var baseUrl = '';
  var webUrl = '';

  EnvConfig({required this.baseUrl, required this.webUrl});
}
